package test;

import org.myhibernate.ProxyTemplate;
import org.myhibernate.Template;
import org.personal.Constants;
import org.personal.entity.Layout;
import org.personal.entity.Page;
import org.personal.entity.Portlet;

public class Demo {

	public static void main(String[] args) 
	{
		//createPage();
		//createLayout();
		createPortlet();
		//addPortletToPage();
		
		
		System.out.println("finish");
	}
	public static void createPage()
	{
		Template<Page> template=new ProxyTemplate(Page.class).getInstance();
		try 
		{
			Page page=template.get("1");
			page.setPagePath("/WEB-INF/jsp/html/wuchuan/person.jsp");
			page.setTitle("个人页面测试");
			page.getUsers().add(Constants.USER_ANONYMOUS);
			page.getUsers().add(Constants.USER_ALLUSER);
			template.update(page);
			
		} catch (Exception e) 
		{
			e.printStackTrace();
		}
		finally
		{
			template.close();
		}
	}
	public static void createLayout()
	{
		Template<Layout> template=new ProxyTemplate(Layout.class).getInstance();
		try 
		{
			Layout layout=new Layout();
			layout.setPagePath("/layout/3column.jsp");
			layout.setTitle("3列布局");
			layout.setDefaultLayout(true);
			template.save(layout);
			
		} catch (Exception e) 
		{
			e.printStackTrace();
		}
		finally
		{
			template.close();
		}
	}
	public static void createPortlet()
	{
		Template<Portlet> template=new ProxyTemplate(Portlet.class).getInstance();
		try 
		{
			Portlet portlet=new Portlet();
			portlet.setPagePath("/WEB-INF/portlet/PicturePortlet.jsp");
			portlet.setTitle("图片");
			portlet.getEditUsers().add("liujun");
			portlet.getUsers().add(Constants.USER_ALLUSER);
			portlet.getUsers().add(Constants.USER_ANONYMOUS);
			template.save(portlet);
			
//			portlet=new Portlet();
//			portlet.setPagePath("/WEB-INF/portlet/NoticePortlet.jsp");
//			portlet.setTitle("通知公告");
//			portlet.setChooseable(true);
//			portlet.getUsers().add(Constants.USER_ALLUSER);
//			portlet.getUsers().add(Constants.USER_ANONYMOUS);
//			template.save(portlet);
			
		} catch (Exception e) 
		{
			e.printStackTrace();
		}
		finally
		{
			template.close();
		}
	}
	public static void addPortletToPage()
	{
		
		Template<Page> template=new ProxyTemplate(Page.class).getInstance();
		try 
		{
			Page page=template.get("1");
			
			page.getPortlets().set(0,"0:0:2");
			page.getPortlets().set(1,"1:0:3");
			
			template.update(page);
			
		} catch (Exception e) 
		{
			e.printStackTrace();
		}
		finally
		{
			template.close();
		}
		
	}
}
